package com.controller;

import com.pojo.GroupCommentImg;
import com.service.GroupCommentImgService;
import com.util.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2020/3/20.
 */
@Api(tags = "用户团购点评图片API")
@Controller
public class GroupCommentImgController {
    @Autowired
    private GroupCommentImgService groupCommentImgService;
    @ApiOperation(value ="添加用户团购点评图片",notes ="" )
    @PostMapping("/groupCommentImg")
    @ResponseBody
    public ServerResponse add(GroupCommentImg groupCommentImg){
        // ServerResponse serverResponse =
        //System.out.println("serverResponse:"+serverResponse);
        return groupCommentImgService.save(groupCommentImg);
    }
    @ApiOperation(value = "删除用户团购点评图片",notes ="修改状态")
    @DeleteMapping("/groupCommentImg/{id}")
    @ResponseBody
    public ServerResponse del(@PathVariable("id")String id){
        ServerResponse serverResponse = groupCommentImgService.modifyStatus(Integer.valueOf(id));
        System.out.println("serverResponse:"+serverResponse);
        return serverResponse;
    }

    @ApiOperation(value ="修改用户团购点评图片",notes ="应该用不到" )
    @PutMapping("/groupCommentImg")
    @ResponseBody
    public ServerResponse upd(GroupCommentImg groupCommentImg){
        System.out.println(groupCommentImg);
        ServerResponse serverResponse = groupCommentImgService.modify(groupCommentImg);
        return serverResponse;
    }
    @ApiOperation(value ="根据用户团购点评图片id查询")
    @GetMapping("/groupCommentImg/{id}")
    @ResponseBody
    public ServerResponse findById(@PathVariable("id") String id){
        System.out.println(id);
        ServerResponse serverResponse = groupCommentImgService.getById(Integer.valueOf(id));
        return serverResponse;
    }

    @ApiOperation(value ="查询用户团购点评图片信息")
    @GetMapping("/groupCommentImg")
    @ResponseBody
    public ServerResponse findAll(){
        ServerResponse serverResponse = groupCommentImgService.getAll();
        return serverResponse;
    }
    @ApiOperation(value = "获得团购评价图片信息的主页面",notes = "团购评价图片信息端")
    @GetMapping("/groupCommentImg/backhome")
    public String goUserBackHome(Model model){
        ServerResponse serverResponse = groupCommentImgService.getAll();
        model.addAttribute("info",serverResponse.getData());
        return "back/group/groupcommentimgbackhome";
    }
}
